//
//  TitleButton.swift
//  swift-GWYWeiBo
//
//  Created by x on 2017/3/14.
//  Copyright © 2017年 HLB. All rights reserved.
//

import UIKit

class TitleButton: UIButton {
    
    //修改导航栏中间的标题位置
    override init(frame: CGRect) {
        super.init(frame: frame)

        setTitleColor(UIColor.darkGray, for: UIControlState.normal)
        setImage(UIImage.init(named: "navigationbar_arrow_down"), for: UIControlState.normal)
        setImage(UIImage.init(named: "navigationbar_arrow_up"), for: UIControlState.selected)
        sizeToFit()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //这个方法要调用两次
    override func layoutSubviews() {
        super.layoutSubviews()
        titleLabel?.frame.origin.x = 0
        imageView?.frame.origin.x = (titleLabel?.bounds.size.width)!
    }
}
